package cn.tedu.crm.engineeringManagement.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import cn.tedu.crm.base.pojo.PageObject;
import cn.tedu.crm.base.response.JsonResult;
import cn.tedu.crm.engineeringManagement.pojo.dto.EngineeringManagementControllerQuery;
import cn.tedu.crm.engineeringManagement.pojo.dto.EngineeringManagementSaveParam;
import cn.tedu.crm.engineeringManagement.pojo.vo.EngineeringManagementVO;
import cn.tedu.crm.engineeringManagement.service.EngineeringManagementService;
import cn.tedu.crm.operatelog.loggable.Loggable;
import cn.tedu.crm.operatelog.loggable.OperationModule;
import cn.tedu.crm.operatelog.loggable.OperationType;
import cn.tedu.crm.orders.mapper.OrdersMapper;
import cn.tedu.crm.orders.pojo.entity.Orders;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@Api(tags = "财务管理工程表")
@Slf4j
@RestController()
@RequestMapping("/api/crm/engineering_management")
public class EngineeringManagementController {

    @Autowired
    private EngineeringManagementService engineeringManagementService;

    @Autowired
    private OrdersMapper ordersMapper;

    @SaCheckPermission("crm:finance:project:select")
    @GetMapping("/select")
    public JsonResult selectDept(EngineeringManagementControllerQuery engineeringManagementControllerQuery) {
        log.debug("查询工程定金表部门信息:{}", engineeringManagementControllerQuery);
        if(engineeringManagementControllerQuery.getId()==null){
            PageObject<EngineeringManagementVO> pageObject = PageObject.page(
                    engineeringManagementControllerQuery.getPageNum(), engineeringManagementControllerQuery.getPageSize(), ()
                            -> engineeringManagementService.selectEngineeringManagementServiceByCustomerId(engineeringManagementControllerQuery));
            return JsonResult.success(pageObject);
        }

        return JsonResult.ok(null);
    }

    @SaCheckPermission("crm:finance:project:add")
    @Loggable(module = OperationModule.DEPOSIT_MANAGEMENT,type = OperationType.INSERT)
    @PostMapping("/insert")
    public JsonResult insertEngineeringManagement(@RequestBody EngineeringManagementSaveParam engineeringManagementSaveParam) {
        log.debug("插入工程订单表服务层:{}", engineeringManagementSaveParam);
        return engineeringManagementService.insertEngineeringManagement(engineeringManagementSaveParam);
    }
}
